<h1 class="th1"><%= t("devise_related_custom_views.edit") %> <%= resource_name.to_s.humanize %></h1>
<div class="columns-12">
  <div class="col-6 col-offset-3">
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { :multipart => true, method: :put }) do |f| %>
      <%= devise_error_messages! %>
      <%= f.label :avatar %>
      <%= image_tag @user.avatar.url(:thumb), :class => 'circle' %>
        <div class="file-upload-container">
          <div class="file-upload-override-button  btn btn-small btn-success left">
            <%= t("devise_related_custom_views.registration_and_edit_details.choose_file") %>
            <%= f.file_field :avatar, :class => 'file-upload-button', :id => 'file-upload-button' %>
          </div>
          <div class="file-upload-filename left" id="file-upload-filename">No file selected</div>
          <div class="both"></div>
        </div>

      <%= f.label :name %>
      <%= f.text_field :name, autofocus: true %>

      <%= f.label :email %>
      <%= f.email_field :email, autofocus: true %>

      <div class='control-group'>
        <%= f.fields_for :sex do |s| %>
            <%= s.label t("devise_related_custom_views.registration_and_edit_details.sex") %>
            <%= s.collection_radio_buttons :sex_id, Sex.all, :id, :name do |cb| %>
              <% cb.label(class: "radio inline") {cb.radio_button(class: "radio") + cb.text} %>
            <% end %>
        <% end %>
      </div>

      <div class='control-group'>
        <%= f.fields_for :major do |m| %>
           <%= m.label t("devise_related_custom_views.registration_and_edit_details.major") %>
           <%= m.collection_select :major_id, Major.all, :id, :name, prompt: true, class: "specify" %>
        <% end %>
      </div>

      <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
        <%= t("devise_related_custom_views.registration_and_edit_details.currently_waiting_confirmation_for") %>: <%= resource.unconfirmed_email %>
      <% end %>

      <%= f.label :time_zone %>
      <%= f.time_zone_select :time_zone %>

      <%= f.label :password %> <i>(<%= t("devise.registrations.edit.leave_blank_if_you_don_t_want_to_change_it") %>)</i>
      <%= f.password_field :password, autocomplete: "off" %>

      <%= f.label :password_confirmation %>
      <%= f.password_field :password_confirmation, autocomplete: "off" %>

      <%= f.label :current_password %> <i>(<%= t("devise.registrations.edit.we_need_your_current_password_to_confirm_your_changes") %>)</i>
      <%= f.password_field :current_password, autocomplete: "off" %>

      <%= f.submit "Update", class: "btn btn-large btn-primary" %>
    <% end %>
    <!-- <h1>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, class: "btn btn-large btn-danger", method: :delete %></h1> -->
  </div>
</div>

<script>
  $("#user_sex_sex_id_<%= @current_user.sex_id %>").attr( 'checked', true )
  $("option[value|='<%= @current_user.major_id %>']").attr( 'selected', true )
  $("#file-upload-button").on("change", function () {
      var fileName = $(this).val().replace('C:\\fakepath\\', '');
      $("#file-upload-filename").html(fileName);
  });
</script>